<template>
  <div class='sub-sort'>
    <div class="sort">
      <a href="javascript:;" :class="{active: subSort === null}" @click="changeSort(null)">默认排序</a>
      <a href="javascript:;" :class="{active: subSort === 'publishTime'}" @click="changeSort('publishTime')">最新商品</a>
      <a href="javascript:;" :class="{active: subSort === 'orderNum'}" @click="changeSort('orderNum')">最高人气</a>
      <a href="javascript:;" :class="{active: subSort === 'evaluateNum'}" @click="changeSort('evaluateNum')">评论最多</a>
    </div>
  </div>
</template>
<script>
import { ref, inject } from 'vue'
export default {
  name: 'SubSort',
  setup () {
    const subSort = ref(null)
    // 引入setSortField这个方法
    const setSortField = inject('setSortField')
    function changeSort (sortType) {
      // 修改交互效果依赖的数据
      subSort.value = sortType
      setSortField(sortType)
    }
    return {
      subSort,
      changeSort
    }
  }
}
</script>
<style scoped lang='less'>
.sub-sort {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .sort {
    display: flex;
    a {
      height: 30px;
      line-height: 28px;
      border: 1px solid #e4e4e4;
      padding: 0 20px;
      margin-right: 20px;
      color: #999;
      border-radius: 2px;
      position: relative;
      transition: all .3s;
      &.active {
        background: @xtxColor;
        border-color: @xtxColor;
        color: #fff;
      }
      .arrow {
        position: absolute;
        border: 5px solid transparent;
        right: 8px;
        &.up {
          top: 3px;
          border-bottom-color: #bbb;
            &.active {
            border-bottom-color: @xtxColor;
          }
        }
        &.down {
          top: 15px;
          border-top-color: #bbb;
          &.active {
            border-top-color: @xtxColor;
          }
        }
      }
    }
  }
  .check {
    .xtx-checkbox {
      margin-left: 20px;
      color: #999;
    }
  }
}
</style>
